<template>
  <div class="detail_box" >
    <Info :gid='Gid' />
    <Main :gid='Gid' />
  </div>
</template>

<script>
import Info from './comps/Info/Info'
import Main from './comps/Main/Main'
import {mapGetters} from 'vuex'
import {addHistory} from 'server/front_k.js'

export default {
  components: {
    Info,
    Main,
  },
  data() {
    return {
      Gid:-1,
    }
  },
  created(){

    if(this.$route.query.gid!=null){//判断是否直接进入详情页
      this.Gid = parseInt(this.$route.query.gid);
      var them = this;
      // window.onload = function(){
      //   them.$router.afterEach((to,from,next)=>{
      //     window,scrollTo(0,0);
      //   })
      // }
    }else{
      var them = this;
      this.$Modal.info({
        title:'请点击商品进入',
        okText:"确定",
        onOk: function() {
          them.$router.push({path:'home'});
        }
      })
    }

    // 判断是否登录
    if (this.getIsLogin) {
     
      this._addHistory()

    }else{

      this.$show.$on('userIsLoginSuccess',this._addHistory)

    }
    

  },
  mounted() {
    setTimeout(()=>{
        window.scrollTo(0,0)
    },500)
    
  },
  computed:{
    ...mapGetters(['getIsLogin'])
  },
  methods:{
    _addHistory(){
  
       const gid = parseInt(this.$route.query.gid);
      addHistory({
        gid,
      }).then(res=>{
      
      })

    }
  }
}
</script>

<style scoped>
  .detail_box{
    width:100%;
    height: 100%;
    background-color: #F9F9F9;
    padding-bottom: 15vw;
  }
</style>
